package com.cloudcc.mobile.weight;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;

/**
 * @Description: listview的空布局
 * @author wangzhiqiang
 * @date 2015-12-14 下午5:15:13
 */
public class EmptyLayout extends LinearLayout {
	private TYPESTATE mType = TYPESTATE.HIDE;

	private LinearLayout containerResult;
	private RelativeLayout containerLoading;
	private TextView no_result_label;
	View iamge;
	public enum TYPESTATE {
		HIDE, LOADING, EMPTY
	}

	public EmptyLayout(Context context) {
		this(context, null);
	}

	public EmptyLayout(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public EmptyLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		stepViews();
	}

	private void stepViews() {
		LayoutInflater.from(getContext()).inflate(
				R.layout.views_load_cloudcc_footer, this);
		containerResult = (LinearLayout) findViewById(R.id.loading_result_container);
		containerLoading = (RelativeLayout) findViewById(R.id.loading_load_container);
		no_result_label = (TextView) findViewById(R.id.no_result_label);
		iamge = containerResult.findViewById(R.id.no_result_image);
//		empty();
	}

	public void hide() {
		mType = TYPESTATE.HIDE;
		containerResult.setVisibility(View.GONE);
		containerLoading.setVisibility(View.GONE);
		setVisibility(View.GONE);
	}

	public void loading() {
		mType = TYPESTATE.LOADING;
		setVisibility(VISIBLE);
		containerResult.setVisibility(View.GONE);
		containerLoading.setVisibility(View.VISIBLE);
		iamge.setVisibility(View.GONE);
		no_result_label.setVisibility(View.GONE);
	}

	public void empty() {
		mType = TYPESTATE.EMPTY;
//		setVisibility(VISIBLE);
		iamge.setVisibility(View.VISIBLE);
		no_result_label.setVisibility(View.VISIBLE);
		no_result_label.setText(getResources().getString(R.string.zwjl_tv));
		containerResult.setVisibility(View.VISIBLE);
		containerLoading.setVisibility(View.GONE);
	}

	public TYPESTATE getEmptyType() {
		return mType;
	}

	public void setEmptyType(TYPESTATE type) {
		if (type == TYPESTATE.HIDE) {// hide
			hide();
		} else if (type == TYPESTATE.LOADING) {// loading
			loading();
		} else if (type == TYPESTATE.EMPTY) {// no data
			empty();
		}
	}

	@Override
	public void setVisibility(int visibility) {
		if (visibility == View.GONE)
			mType = TYPESTATE.HIDE;
		super.setVisibility(visibility);
	}

}
